<body>
    <link href="./Public/Admin/css/H-ui.min.css" rel="stylesheet" type="text/css">
	<script type="text/javascript" src="./Public/Admin/lib/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript" src="./Public/Admin/lib/layer/1.9.3/layer.js"></script>
	<link rel="stylesheet" href="./Public/Admin/lib/layer/1.9.3/skin/layer.css" id="layui_layer_skinlayercss">
<style type="text/css">
        .col-lg-10 {
            margin: 12px auto;
            float: none;
            overflow: auto;
        }

        .input-text, .select-box {
            border-color: #ccc;
        }

        .input-control {
            float: left;
            margin-right: 8px;
        }

        input {
            font-size: 24px;
            font-weight: bolder;
        }
		tfoot tr:first-child td{
			font-size:18px;
			font-weight:bold;
		}
		.border{
			border: #00c393 solid 1px;
			border-radius: 4px;
			height:auto;
			overflow: auto;
			width:50%;
		}
</style>

<div class="container">
    <div class="col-lg-10">
        <input class="input-text radius size-XL" id="saom" name="saom" type="text" placeholder="请扫描{:C('scanorder.lang_name')}"/>
        <span>*按Ctrl+0将焦点移到扫描筐</span>
    </div>
    <div class="col-lg-10">
        <input style="margin: 12px 0;" id="pack_weight" class="input-control input-text radius size-L" type="text"
               placeholder="包裹重量(KG)"/>
        <input id="sub" class="btn btn-success radius size-XL" type="button" value="确认"/>
		<input id="history" class="btn btn-success radius size-XL" type="button" value="历史列表"/>
    </div>
	<div class='col-lg-10'>
        <table class="table border table-border">
            <tbody>
				<tr class="success">
					<td>序号</td>
					<td>面单编号</td>
					<td>重量</td>
				</tr>
			</tbody>
			<tfoot>
				
			</tfoot>
		</table>
    </div>
</div>
<script type="text/javascript">
	 //切换链接
	var index_mailno=0;
	function redirect(){
		url="{:U('packing')}";
		window.parent.showTab(url,'打包');
		window.location.href=window.location.href;
	}
	$('#history').click(function(){
		window.parent.showTab('./index.php?s=ScanOrder/packing_list','包裹列表');
	})
    $("#saom").focus();
    $(document).keydown(function (event) {
        if (event.ctrlKey && event.keyCode == 48) {
            $("#saom").focus();
        }
    });
    var index = 0;//此时状态为扫描{:C("scanorder.lang_name")}
    var saom = '';//成功的{:C("scanorder.lang_name")}号
    $("#saom").keydown(function (event) {
        if (event.keyCode == 13) {
            if ($("#saom").val() == '') {
				play_audio_file('failed');
                alerts('{:C("scanorder.lang_name")}号不能为空！');
            }else{
				$("#pack_weight").focus();
			}
        }
    });
	$("#pack_weight").keydown(function (event) {
        if (event.keyCode == 13) {
            $('#sub').click();
        }
    });
    $("#sub").on("click", function () {
		mail_no=$("#saom").val();
		weight=$('#pack_weight').val();
		alert_weight="{:C('base_config.alert_weight')}";
		if(alert_weight==""){
			alerts('请设置超重重量！');
			play_audio_file('failed');
			return false;
		}
		<!-- if(weight>=alert_weight){ -->
			<!-- alerts('重量不能大于'+alert_weight+'kg！'); -->
			<!-- play_audio_file('failed'); -->
			<!-- return false; -->
		<!-- } -->
        if ($("#saom").val() == '') {
            alerts('{:C("scanorder.lang_name")}号不能为空！');
			play_audio_file('failed');
			$("#saom").focus();
            return false;
        }
        if ($("#pack_weight").val() == '') {
            alerts('重量不能为空！');
			play_audio_file('failed');
            return false;
        }
		
		var green="{:I('green')}";
		
		var pack_url="__APP__/ScanOrder/weighed";
		
		if(green==1){
			$.post(pack_url,{order_no:$('#saom').val(),weight:$('#pack_weight').val(),green:1},function(msg){
				if (msg.flag == 0) {
					play_audio_file('failed');
					alerts(msg.data);
				}
				else {
					play_audio_file('success');
					alerts(msg.data);
					$("input[type=text]").prop("value",'');
					index_mailno++;
					$(".border tfoot").prepend("<tr><td>"+index_mailno+"</td><td>"+mail_no+"</td><td>"+weight+"</td></tr>");
					$("#saom").focus();
					var auto_redirect={:C('base_config.auto_redirect')};
					if(auto_redirect==1){
						redirect();
					}
				}
			},'json');
		}else{
			$.post(pack_url,{order_no:$('#saom').val(),weight:$('#pack_weight').val()},function(msg){
				if (msg.flag == 0) {
					play_audio_file('failed');
					alerts(msg.data);
				}
				else {
					play_audio_file('success');
					alerts(msg.data);
					$("input[type=text]").prop("value",'');
					index_mailno++;
					$(".border tfoot").prepend("<tr><td>"+index_mailno+"</td><td>"+mail_no+"</td><td>"+weight+"</td></tr>");
					$("#saom").focus();
					var auto_redirect={:C('base_config.auto_redirect')};
					if(auto_redirect==1){
						redirect();
					}
				}
			},'json');
		}
    });
    function alerts(msg) {
        var index = layer.open({
            type: 0,
            title: '系统提示',
            content: msg,
            shift: 2,
            btn: ['知道了'],
            time: 1200,
            offset: '120px',
            yes: function () {
                layer.close(index);
            }
        });
        $("#saom").prop("value", '');
    }
	function play_audio_file(filename) {
        var url = "__PUBLIC__";
        if ($("audio").length == 0) {
            $("body").append($("<audio src='' autoplay></audio>"));
        }
        $("audio").attr('src', url + '/Admin/Voice/'+filename+'.wav');
    }
</script>
</body>
